<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8" v-if="true">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:notice:add']">新增</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="钱包地址" align="center" prop="address" />
      <el-table-column label="类型" align="center">
        <template #default="scope">
          {{ scope.row.role == 2 ? '24将' : '108将' }}
        </template>
      </el-table-column>
      <el-table-column label="可领取时间" align="center">
        <template #default="scope">
          {{ arrMouth[scope.row.month].label }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button type="primary" @click="handleView(scope.row, scope.index)">设置领取时间</el-button>
        </template>
      </el-table-column>
    </el-table>



    <!-- 添加或修改空投对话框 -->
    <el-dialog :title="title" v-model="open" width="600px" append-to-body>
      <el-form ref="noticeRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="钱包地址" prop="address">
          <el-input v-model="form.address" type='text' placeholder="请输入钱包地址" />
        </el-form-item>
        <el-form-item label="钱包类型" prop="planId">
          <el-select class="flex-1" style="flex: 1;" v-model="form.planId" placeholder="">
            <el-option v-for="item in [
              {
                label: '24将',
                value: 2
              },
              {
                label: '108将',
                value: 3
              }
            ]" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 设置领取 -->
    <el-dialog title="领取收益" v-model="openModel" width="600px" append-to-body>
      <el-form ref="noticeRefmodel" :model="modalObj" :rules="rules" label-width="80px">
        <el-form-item label="钱包地址" prop="address">
          <el-input v-model="modalObj.address" disabled type='text' placeholder="请输入钱包地址" />
        </el-form-item>
        <el-form-item label="领取时间" prop="month">
          <el-select class="flex-1" style="flex: 1;" v-model="modalObj.month" placeholder="">
            <el-option v-for="item in [
              {
                label: '1月',
                value: 0
              },
              {
                label: '2月',
                value: 1
              },
              {
                label: '3月',
                value: 2
              },
              {
                label: '4月',
                value: 3
              },
              {
                label: '5月',
                value: 4
              },
              {
                label: '6月',
                value: 5
              },
              {
                label: '7月',
                value: 6
              },
              {
                label: '8月',
                value: 7
              },
              {
                label: '9月',
                value: 8
              },
              {
                label: '10月',
                value: 9
              },
              {
                label: '11月',
                value: 10
              },
              {
                label: '12月',
                value: 11
              }
            ]" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitFormodel">确 定</el-button>
          <el-button @click="cancelmodel">取 消</el-button>
        </div>
      </template>
    </el-dialog>




  </div>
</template>

<script setup name="Notice">
import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice";

import { vestingbeneficiaries, vestingaddBeneficiarie, GeesisPartner } from '@/api/systemSetting/systemSetting.js';
const { proxy } = getCurrentInstance();


const arrMouth = [
  {
    label: '1月',
    value: 0
  },
  {
    label: '2月',
    value: 1
  },
  {
    label: '3月',
    value: 2
  },
  {
    label: '4月',
    value: 3
  },
  {
    label: '5月',
    value: 4
  },
  {
    label: '6月',
    value: 5
  },
  {
    label: '7月',
    value: 6
  },
  {
    label: '8月',
    value: 7
  },
  {
    label: '9月',
    value: 8
  },
  {
    label: '10月',
    value: 9
  },
  {
    label: '11月',
    value: 10
  },
  {
    label: '12月',
    value: 11
  }
]

/*  */
let openModel = ref(false)
const modalObj = ref({
  address: "",
  month: "",
})
/* 打开领取 */
const handleView = (row) => {
  openModel.value = true;
  modalObj.value.address = row.address
}
/** 表单重置 */
function resetmodel() {
  modalObj.value = {
    address: "",
    month: "",
  };
  proxy.resetForm("noticeRefmodel");
}
/** 取消按钮 */
function cancelmodel() {
  openModel.value = false;
  resetmodel();
}
/** 提交按钮 */
function submitFormodel() {
  proxy.$refs["noticeRefmodel"].validate(valid => {
    if (valid) {
      GeesisPartner(modalObj.value).then(response => {
        proxy.$modal.msgSuccess("设置成功");
        openModel.value = false;
        getList();
      });
    }
  });
}

const noticeList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    address: undefined,
    createBy: undefined,
    status: undefined
  },
  rules: {
    address: [{ required: true, message: "参数不能为空", trigger: "blur" }],
    // noticeType: [{ required: true, message: "空投类型不能为空", trigger: "change" }]
  },
});

const { queryParams, form, rules } = toRefs(data);



const getList = async () => {
  loading.value = true;
  let res = await vestingbeneficiaries(queryParams.value)
  console.log(res, 'res vestingbeneficiaries');

  // const arrayData = Object.values(res.data);
  // noticeList.value = arrayData
  noticeList.value = res.data
  // total.value = 0;
  loading.value = false;
}
/** 查询空投列表 */
// function getList() {


//   vestingbeneficiaries(queryParams.value).then(response => {
//     /*  */
//     const arrayData = Object.values(response.data);



//     noticeList.value = arrayData
//     total.value = 0;
//     loading.value = false;
//   });
// }
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}
/** 表单重置 */
function reset() {
  form.value = {
    address: ''
  };
  proxy.resetForm("noticeRef");
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加108、24将";
}
/**修改按钮操作 */
function handleUpdate(row) {
  reset();
  form.value = { ...row };
  open.value = true;
  title.value = "修改空投";
  console.log(form.value, 'vlaue22')
  return;
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["noticeRef"].validate(valid => {
    if (valid) {
      vestingaddBeneficiarie(form.value).then(response => {
        proxy.$modal.msgSuccess("新增成功");
        open.value = false;
        getList();
      });
      return
      if (form.value.id != undefined) {

      } else {
        // addNotice(form.value).then(response => {
        //   proxy.$modal.msgSuccess("新增成功");
        //   open.value = false;
        //   getList();
        // });

      }
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const noticeIds = row.noticeId || ids.value
  proxy.$modal.confirm('是否确认删除空投编号为"' + noticeIds + '"的数据项？').then(function () {
    return delNotice(noticeIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}
getList();
</script>
